<?php get_header(); ?>
<!-- 文章页面开始 -->
<div id="single_main" class="main am-margin-top-sm am-margin-bottom-xl">
    <div class="am-g am-g-fixed single am-padding-vertical-xl">
        <div class="am-u-md-8">
            <h1 class="single_title am-margin-0 yu-text-normal am-text-xl"><?php single_post_title() ?></h1>
            <div class="single_info">
                <span class="am-margin-right">作者：<span class="am-badge am-badge-primary"><?php the_author(); ?></span></span>
            </div>
            <div class="signle_cont">
                <?php if ( have_posts() ) : ?>
                  <?php while ( have_posts() ) : the_post(); ?>
                    <?php the_content(); ?>
                  <?php endwhile; ?>
                <?php endif; ?>
            </div>
            <ul class="am-pagination">
              <li class="am-pagination-prev"><a href="<?php previous_post_link(‘%link’) ?>"><i class="am-icon-angle-left"></i>上一页</a></li>
              <li class="am-pagination-next"><a href="<?php next_post_link(‘%link‘) ?>">下一页 <i class="am-icon-angle-right"></i></a></li>
            </ul>
        </div>
        <div class="am-u-md-4 ">
            <div class="sider_bar am-padding am-margin-bottom-sm">
                <div class="tilte am-text-lg">最新文章</div>
                <ul class="news_list am-padding-left">
                    <?php
                        $args = array( 'posts_per_page' => 10, 'order'=> 'ASC', 'orderby' => 'title' );
                        $rand_posts = get_posts( $args );
                        foreach( $rand_posts as $post ) : ?>
                        <li class="am-margin-bottom-sm">
                            <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><span class="am-badge am-round am-fr"><?php the_date('Y-m-d'); ?></span>
                        </li>
                    <?php endforeach; ?>
                </ul>
            </div>
            <div class="sider_bar am-padding am-margin-bottom-sm">
                <div class="tilte am-text-lg">相关文章</div>
                <ul class="rand_list">
<?php
global $post;
$cats = wp_get_post_categories($post->ID);
if ($cats) {
    $args = array(
          'category__in' => array( $cats[0] ),
          'post__not_in' => array( $post->ID ),
          'showposts' => 6,
          'caller_get_posts' => 1
      );
  query_posts($args);
  if (have_posts()) {
    while (have_posts()) {
        the_post(); update_post_caches($posts); ?>
        <li class="am-margin-bottom-sm">
            <a href="<?php the_permalink(); ?>">
                <?php
                    if(has_post_thumbnail()){ 
                        echo the_post_thumbnail('post-thumbnail-464-200');
                    } else {
                        echo '<img src="'.get_template_directory_uri().'/assets/imgs/tem_logo.jpg">';
                    }
                ?>
            </a>
            <h4 class="art_title am-text-sm yu-text-normal am-text-center am-margin-0"><?php the_title(); ?></h4>
        </li>
<?php
    }
  } 
  else {
    echo '<li>* 暂无相关文章</li>';
  }
  wp_reset_query(); 
}
else {
  echo '<li>* 暂无相关文章</li>';
}
?>

                    <?php
                        $args = array( 'posts_per_page' => 5, 'orderby' => 'rand' );
                        $rand_posts = get_posts( $args );
                        foreach( $rand_posts as $post ) : ?>
                        <li class="am-margin-bottom-sm">
                            <a href="<?php the_permalink(); ?>">
                                <?php
                                    if(has_post_thumbnail()){ 
                                        echo the_post_thumbnail('post-thumbnail-464-200');
                                    } else {
                                        echo '<img src="'.get_template_directory_uri().'/assets/imgs/tem_logo.jpg">';
                                    }
                                ?>
                            </a>
                            <h4 class="art_title am-text-sm yu-text-normal am-text-center am-margin-0"><?php the_title(); ?></h4>
                        </li>
                    <?php endforeach; ?>
                </ul>
            </div>
        </div>
        <div class="am-cf"></div>
    </div>
</div>
<!-- 文章页面结束 -->
<?php get_footer(); ?>


